#include "Game.h"
#include <iostream>
#include <algorithm>
#include <memory>
#include <vector>
#include <random>
#include "Utils.h"
namespace BncImb {
namespace Domain {
using namespace std;
void Game::initialize() {
	this->createTiles();
	this->createRandomTiles();
	Utils::printNumbered(mTiles.begin(), mTiles.end(), [&](shared_ptr<Tile> t) { return t->label(); });	
}

void Game::createTiles() {
	mTiles.push_back(make_shared<SpecialTile>(TileType::begin));
	mTiles.push_back(make_shared<TerrainTile>("Av. 9 de Julho", ColorType::green, 1.1));
	mTiles.push_back(make_shared<TerrainTile>("Av. Brasil", ColorType::green, 1.2));
	mTiles.push_back(make_shared<StockTile>("Itau"));
	mTiles.push_back(make_shared<TerrainTile>("Av. Beira Mar", ColorType::green, 1.3));
	mTiles.push_back(make_shared<TerrainTile>("Av. Rio Branco", ColorType::red, 2.1));
	mTiles.push_back(make_shared<SpecialTile>(TileType::news));
	mTiles.push_back(make_shared<TerrainTile>("Av. do Estado", ColorType::red, 2.2));
	mTiles.push_back(make_shared<StockTile>("TAM"));
	mTiles.push_back(make_shared<TerrainTile>("Av. do Contorno", ColorType::red, 2.1));
	mTiles.push_back(make_shared<SpecialTile>(TileType::jail));
	mTiles.push_back(make_shared<SpecialTile>(TileType::news));
	mTiles.push_back(make_shared<TerrainTile>("Av. Reboucas", ColorType::blue, 2.0));
	mTiles.push_back(make_shared<TerrainTile>("Av. Santo Amaro", ColorType::blue, 1.9));
	mTiles.push_back(make_shared<StockTile>("Ipiranga"));
	mTiles.push_back(make_shared<TerrainTile>("Rua da Consolacao", ColorType::blue, 1.9));
	mTiles.push_back(make_shared<ValueTile>(2000));
	mTiles.push_back(make_shared<TerrainTile>("Av Morumbi", ColorType::pink, 6.0));
	mTiles.push_back(make_shared<TerrainTile>("Av. Higienopolis", ColorType::pink, 5.8));
	mTiles.push_back(make_shared<TerrainTile>("Av. Sao Joao", ColorType::purple, 1.5));
	mTiles.push_back(make_shared<SpecialTile>(TileType::vacation));
	mTiles.push_back(make_shared<TerrainTile>("Av. Ipiranga", ColorType::purple, 1.4));
	mTiles.push_back(make_shared<StockTile>("Nivea"));
	mTiles.push_back(make_shared<ValueTile>(-2000));
	mTiles.push_back(make_shared<SpecialTile>(TileType::news));
	mTiles.push_back(make_shared<TerrainTile>("Rua Brigadeiro Faria Lima", ColorType::darkBlue, 1.4));
	mTiles.push_back(make_shared<TerrainTile>("Av. Paulista", ColorType::darkBlue, 1.5));
	mTiles.push_back(make_shared<SpecialTile>(TileType::news));
	mTiles.push_back(make_shared<TerrainTile>("Av. Recife", ColorType::darkBlue, 1.4));
	mTiles.push_back(make_shared<StockTile>("VIVO"));
	mTiles.push_back(make_shared<SpecialTile>(TileType::goToJail));
	mTiles.push_back(make_shared<TerrainTile>("Av. Juscelino Kubitschek", ColorType::orange, 3.3));
	mTiles.push_back(make_shared<SpecialTile>(TileType::news));
	mTiles.push_back(make_shared<TerrainTile>("Rua Oscar Freire", ColorType::orange, 3.2));
	mTiles.push_back(make_shared<TerrainTile>("Av. Ibirapuera", ColorType::orange, 3.2));
	mTiles.push_back(make_shared<TerrainTile>("Av. Vieira Souto", ColorType::yellow, 2.6));
	mTiles.push_back(make_shared<StockTile>("FIAT"));
	mTiles.push_back(make_shared<TerrainTile>("Av. Presidente Vargas", ColorType::yellow, 2.5));
	mTiles.push_back(make_shared<SpecialTile>(TileType::news));
	mTiles.push_back(make_shared<TerrainTile>("Av. Niemeyer", ColorType::yellow, 2.6));
}

void Game::createRandomTiles() {
	vector<int> possibleValues = { -300, -200, -100, 100, 200, 300 };
	vector<shared_ptr<News>> news;

	random_device rd;
	default_random_engine e1(rd());
	uniform_int_distribution<int> uniform_dist(0, possibleValues.size() - 1);
	
	for (int i = 0; i < 20; i++) {
		news.push_back(make_shared<News>(NewsType::money, possibleValues[uniform_dist(e1)]));
	}

	news.insert(
		news.begin() + uniform_int_distribution<int>(0, news.size() - 1)(e1),
		make_shared<News>(NewsType::jailKey));


	news.insert(
		news.begin() + uniform_int_distribution<int>(0, news.size() - 1)(e1),
		make_shared<News>(NewsType::goToJail));
	
	for (shared_ptr<News> newsPtr : news) {
		mNews.push(newsPtr);
	}
}
}
}
